The first task involved getting Firmata up and running in relation between an Arduino board and a Processing sketch.

In the very next task we were scheduled to receive particular forms of input transferred from Processing into Arduino. In this case, instead of using a regular diode, I utilized a RGB LED diode. I also tried getting the ultrasonic sensor working, although failed due to some Processing-related syntax problems. In addition, I have used PWM pins.

For the following task we were asked to get signals from an Arduino board into Processing sketch. For this, I decided to combine my photosensitive resistor (light sensor) and throw some cool stuff along into the processing sketch. At first to draw simple dots, then afterwards some squares, culminating with circles being coloured accordingly, in relation to the mouse's position and light sensor values.




The biggest challenge was to get the ultrasonic sensor working, along with transferring Arduino sketches into Processing/Firmata merger. It's relatively straightforward although confusing as the documentation is relatively scarce.

The next challenge was in relation to getting an interesting interaction between Arduino, Processing and RGB LED. After all, there are three dimensions to work with, however, a screen is two-dimensional, therefore if I wanted to allocate my mouse cursor horizontally and vertically, I would only be able to manipulate two of the following colours: Red, Green and/or Blue. The solution was to introduce the photosensitive resistor as the third dimension, which ultimately worked as a the red colour. The more intensive the light, the more intensive the red diode. It worked surprisingly nicely.



- I managed to get the input/output working (in general)

- I was able to figure out how to manipulate three RGB LED diodes by the use of three different inputs. Apart from the mouse's X and Y position, I utilised a photosensitive resistor, complementing the three-dimensional picture

- I looked into how Firmata works and was able to effectively use it in relation to a few Arduino-based sensors

- I ran the Happy/Sad face sketch successfully and managed to get it up and running in relation to an ultrasonic sensor



- I didn't get the ultrasonic sensor working. Also I had to remap the colours associated with the RGB LED and the ellipses drawn in Processing

- In relation to aforementioned, in contrary to what I have just said, I did get the ultrasonic sensor working, although the readings quickly became to erratic to make use of, subsequently the sketch was relatively unreliable

- Syntax differences once Firmata is used are eerie

- Type mismatches slow down the work efficiency


//Arduino Code

      /*
/*
arduino_pwm

Demonstrates the control of analog output (PWM) pins of an Arduino board
running the StandardFirmata firmware.  Moving the mouse horizontally across
the sketch changes the output on pins 9 (value is proportional to the mouse
X coordinate) and 11 (inversely porportional to mouse X).

To use:
* Using the Arduino software, upload the StandardFirmata example (located
  in Examples > Firmata > StandardFirmata) to your Arduino board.
* Run this sketch and look at the list of serial ports printed in the
  message area below. Note the index of the port corresponding to your
  Arduino board (the numbering starts at 0).  (Unless your Arduino board
  happens to be at index 0 in the list, the sketch probably won't work.
  Stop it and proceed with the instructions.)
* Modify the "arduino = new Arduino(...)" line below, changing the number
  in Arduino.list()[0] to the number corresponding to the serial port of
  your Arduino board.  Alternatively, you can replace Arduino.list()[0]
  with the name of the serial port, in double quotes, e.g. "COM5" on Windows
  or "/dev/tty.usbmodem621" on Mac.
* Connect LEDs or other outputs to pins 9 and 11.
* Run this sketch and move your mouse horizontally across the screen.
  
For more information, see: http://playground.arduino.cc/Interfacing/Processing
*/

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

int u_pin= 11;
int A0;

void setup() {

  
  size(1000, 1000);

  // Prints out the available serial ports.
  println(Arduino.list());
  
  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list
  // printed by the line above).
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  
  // Alternatively, use the name of the serial port corresponding to your
  // Arduino (in double-quotes), as in the following line.
  //arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);
}

void draw() {
  

  
  
  fill(constrain(255-mouseY/2, 0, 255), constrain(arduino.analogRead(A0),0,255), constrain(255 - mouseX/2,0,255));
  ellipse(arduino.analogRead(A0),arduino.analogRead(A0), arduino.analogRead(A0), arduino.analogRead(A0));
  println(constrain(255-mouseY/2, 0, 255), constrain(arduino.analogRead(A0),0,255), constrain(255 - mouseX/2,0,255));
  
  // Output analog values (PWM waves) to digital pins 9 and 11.
  // Note that only certain Arduino pins support analog output (PWM).
  // See the documentation for your board for details.
  arduino.analogWrite(11, constrain(255-mouseY/2, 0, 255));
  arduino.analogWrite(10, constrain(255 - mouseX / 2, 0, 255));
  arduino.analogWrite(9, constrain(arduino.analogRead(A0),0,255));
}

void pulseIn (int a, int b){
}


  //Processing

  /*
arduino_pwm

Demonstrates the control of analog output (PWM) pins of an Arduino board
running the StandardFirmata firmware.  Moving the mouse horizontally across
the sketch changes the output on pins 9 (value is proportional to the mouse
X coordinate) and 11 (inversely porportional to mouse X).

To use:
* Using the Arduino software, upload the StandardFirmata example (located
  in Examples > Firmata > StandardFirmata) to your Arduino board.
* Run this sketch and look at the list of serial ports printed in the
  message area below. Note the index of the port corresponding to your
  Arduino board (the numbering starts at 0).  (Unless your Arduino board
  happens to be at index 0 in the list, the sketch probably won't work.
  Stop it and proceed with the instructions.)
* Modify the "arduino = new Arduino(...)" line below, changing the number
  in Arduino.list()[0] to the number corresponding to the serial port of
  your Arduino board.  Alternatively, you can replace Arduino.list()[0]
  with the name of the serial port, in double quotes, e.g. "COM5" on Windows
  or "/dev/tty.usbmodem621" on Mac.
* Connect LEDs or other outputs to pins 9 and 11.
* Run this sketch and move your mouse horizontally across the screen.
  
For more information, see: http://playground.arduino.cc/Interfacing/Processing
*/

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

int u_pin= 11;
int A0;
float pulseIn(int,int);

void setup() {

  
  size(1000, 1000);

  // Prints out the available serial ports.
  println(Arduino.list());
  
  // Modify this line, by changing the "0" to the index of the serial
  // port corresponding to your Arduino board (as it appears in the list
  // printed by the line above).
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  
  // Alternatively, use the name of the serial port corresponding to your
  // Arduino (in double-quotes), as in the following line.
  //arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);
}

void draw() {
  
  float duration, distance;
  arduino.digitalWrite(12, 1);  // Added this line
  delay(2); // Added this line
  arduino.digitalWrite(12, 0);
//  delayMicroseconds(1000); - Removed this line
  delay(10); // Added this line
  arduino.digitalWrite(12, 0);
  duration = pulseIn(13, 0);
  distance = (duration/2) / 29.1;
  if (distance < 4) {  // This is where the LED On/Off happens
  arduino.digitalWrite(10,255);
  }
  
  fill(constrain(255-mouseY/2, 0, 255), constrain(arduino.analogRead(A0),0,255), constrain(255 - mouseX/2,0,255));
  ellipse(arduino.analogRead(A0),arduino.analogRead(A0), arduino.analogRead(A0), arduino.analogRead(A0));
  println(constrain(255-mouseY/2, 0, 255), constrain(arduino.analogRead(A0),0,255), constrain(255 - mouseX/2,0,255));
  
  // Output analog values (PWM waves) to digital pins 9 and 11.
  // Note that only certain Arduino pins support analog output (PWM).
  // See the documentation for your board for details.
  arduino.analogWrite(11, constrain(255-mouseY/2, 0, 255));
  arduino.analogWrite(10, constrain(255 - mouseX / 2, 0, 255));
  arduino.analogWrite(9, constrain(arduino.analogRead(A0),0,255));
}

  //Arduino code

  #include 

#define TRIGGER_PIN  12
#define ECHO_PIN  13
#define LED_PIN 9
#define LED_PIN2 10
#define LED_PIN3 11

#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);


byte brightness;
long rangeInCentimeters;

void setup() {
  mySerial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  pinMode(LED_PIN, OUTPUT);
  pinMode(LED_PIN2, OUTPUT);
  pinMode(LED_PIN3, OUTPUT);
}

void loop() {
  delay(20);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
   unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds.
  int cm = sonar.ping_cm();

    int rangeInCentimeters = (uS / US_ROUNDTRIP_CM); 
    
    
     if (rangeInCentimeters > 50 && rangeInCentimeters < 100) {
        analogWrite(LED_PIN, 0);
        analogWrite(LED_PIN2, 255);
        analogWrite(LED_PIN3, 255);
        mySerial.println("a");
    } else if (rangeInCentimeters >= 10 && rangeInCentimeters <=50){
      analogWrite(LED_PIN, 0);
      analogWrite(LED_PIN2, 0);
      analogWrite(LED_PIN3, 255);
      mySerial.println("b");
    }
        else if (rangeInCentimeters >100){
            // set the brightness of the LED:
      analogWrite(LED_PIN, 255); //blue
      analogWrite(LED_PIN2, 0); //green
      analogWrite(LED_PIN3, 0); //red
    }
    else{}
  }


I think that I would find a way to map the results on the processing sketch in a neatier way. In my case it was a rather one-dimensional case, so I would probably introduce another way of manipulating the sketch by using not only the photosensitive resistor but also perhaps the ultrasonic sensor, introducing a two-dimensional control and perhaps another module, which could invoke a 3-dimensional features, such as increasing the ellipses size. While the current setup with mouseX and mouseY was sufficient, there is a myriad of solutions yet to be explored

Notwithstanding, I still think that my setup was quite good and interesting, and featured some functionality that could project into other spheres of interest and development



First of all, the photosensitive resistor could potentially be used as a controller, based on how it behaved in my project. Secondly, logics introduced into processing and arduino in conjunction with serial communication can produce promising results. The more modules incorporated, the more flexibility and engaging project could be developed. At this point I was able to program a single RGB LED. What happens once I introduce an RGB LED Strip? The dimensions in which Arduino could be programmed could go into a myriad, I believe at this point the developer is just constrained by skills, knowledge and especially: the imagination



I think especially the ultrasonic sensor may introduce a large difference due to its ability to monitor the enironment. Any changes can get picked up relatively fast and therefore the creation of highly responsive devices may be introduced surprisingly easy. I'm a bit worried about the precision and glitches, though, but I'll try solving them once I encounter such

From other ideas, it is by firm belief that working with dimensions could become the cornerstone of our project. Although, the precision of our modules remains one tricky subject